#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@Filename      :remail.py
@Description   :正则表达式-电子邮箱
@Datetime      :2020/09/13 20:59:03
@Author        :AshJo
@Version       :v1.0
"""

import re

# 长字符串中提取邮箱地址的正则表达式

test_str = '<email_address>a2164354@qq.com<email>|164544cj@163.com'

# mail_re = '\w+@[A-Za-z0-9]+\.+[A-Za-z]{2,14}'

# 实现精准匹配，固定检查字符串的长度(限制了开头和结尾的内容)
mail_re = r'^[0-9a-zA-Z_]{0,19}@[0-9a-zA-Z]{1,13}\.[com,cn,net]{1,3}$'

result = re.findall(mail_re, test_str)

# 注意：re.match总会从字符串的开头开始匹配
# result = re.match(mail_re, test_str)

print(result)


# 判断邮箱地址格式
# def check_mail(mail_address):
#     if re.match(mail_re, mail_address):
#         print("E-mail Address is True")
#         return True
#     else:
#         print("E-mail Address is False")
#         return False


# mail_address = input('输入邮箱地址：')
# check_mail(mail_address)
